package com.easywan.web.actions;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.easywan.core.BaseController;
import com.easywan.pojo.IResult;
import com.easywan.service.IBaseManagerMenueResService;
import com.easywan.service.IBaseManagerUserService;
import com.easywan.vo.BaseManagerUser;


@Controller
public class IndexController extends BaseController{
	private static Logger logger = Logger.getLogger(IndexController.class);
	@Autowired
	private IBaseManagerUserService managerUserService;
	@Autowired
	IBaseManagerMenueResService menueService;
	/*@Autowired
	private IToolsIdCardService idCardService;*/
	@RequestMapping("index")
	public String index(){
		//System.out.println(menueService.listAllPage().toString());
		//System.out.println(idCardService.idCardCreate());
		return "index.jsp";
	}
	@ResponseBody
	@RequestMapping("menueList")
	public String menue(){
		IResult result = menueService.listAllPage();
		return toJSON(result);
	}
	@RequestMapping("login")
	public String login(){
		return "login.jsp";
	}
	
	@RequestMapping("toLogin")
	public String login(HttpServletRequest request){
		String resultUrl = "redirect:/index.html";
		try{
			String name = getString(request,"name");
			String pwd = getPwd(request,"pwd");
			logger.info("用户登录:"+name + ":" + pwd);
			BaseManagerUser user = managerUserService.login(name,pwd);
			setUserInfo(request, user);
		}catch(Exception e){
			logger.info("登录失败（失败原因）："+e.getMessage());
			resultUrl = "redirect:/login.html";
		}
		
		return resultUrl;
	}

}
